package com.lcf.system.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.lcf.framework.vo.PageVO;
import com.lcf.system.dto.StoreDTO;
import com.lcf.system.query.StorePageQuery;
import com.lcf.system.service.StoreService;
import com.lcf.system.vo.StoreVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 店铺(Store)表控制层
 *
 * @author lcf
 * @since 2025-05-02 11:55:02
 */
@Tag(name = "店铺")
@RestController
@RequestMapping("store")
public class StoreController {
    @Resource
    private StoreService storeService;

    /**
     * 新增
     */
    @Operation(summary = "新增")
    @SaCheckPermission("store:add")
    @PostMapping("add")
    public boolean addStore(@RequestBody @Validated StoreDTO dto) {
        return storeService.addStore(dto);
    }

    /**
     * 删除
     */
    @Operation(summary = "删除")
    @SaCheckPermission("store:delete")
    @DeleteMapping("{id}")
    public boolean deleteStore(@PathVariable @Schema(description = "店铺id") long id) {
        return storeService.deleteStore(id);
    }

    /**
     * 修改
     */
    @Operation(summary = "修改")
    @SaCheckPermission("store:update")
    @PatchMapping("{id}")
    public boolean updateStore(@PathVariable @Schema(description = "店铺id") long id,
                               @RequestBody @Validated StoreDTO dto) {
        return storeService.updateStore(id, dto);
    }

    /**
     * 获取
     */
    @Operation(summary = "根据id查询")
    @SaCheckPermission("store:get")
    @GetMapping("{id}")
    public StoreVO getStore(@PathVariable @Schema(description = "店铺id") long id) {
        return storeService.getStore(id);
    }
    /**
     * 根据用户id获取
     */
    @Operation(summary = "根据userid查询")
    @SaCheckPermission("store:get")
    @GetMapping("user")
    public StoreVO getUserStore() {
        return storeService.getUserStore();
    }

    /**
     * 获取列表
     */
    @Operation(summary = "分页查询")
    @SaCheckPermission("store:list")
    @GetMapping("page")
    public PageVO<StoreVO> getStoreList(StorePageQuery query) {
        return storeService.getStoreList(query);
    }
}


